<?php
require 'JSON.php';

$arr =  array(
		"Nikola Tesla" => 
			array(
			'Let the future tell the truth, and evaluate each one according to his work and accomplishments. The present is theirs, the future, for which I have really worked, is mine.',
			'I do not think there is any thrill that can go through the human heart like that felt by the inventor as he sees some creation of the brain unfolding to success... Such emotions make a man forget food, sleep, friends, love, everything.'
			)
		,
		"Stephen Fry" => 
			array(
			'An original idea. That cant be too hard. The library must be full of them.',
			'But happiness is no respecter of persons.',
			'Christmas to a child is the first terrible proof that to travel hopefully is better than to arrive.'
			)
		,
		"Pablo Picasso" => 
			array(
			'To make oneself hated is more difficult than to make oneself loved.',
			'Action is the foundational key to all success.'
			)
		,
		"Wilbur Wright" => 
			array(
			'It is possible to fly without motors, but not without knowledge and skill.',
			'We could hardly wait to get up in the morning. '
			)
		
	);
/*
function authorlist()
{
	global $arr;
	$result = array();
	foreach($arr as $key=>$value)
	{
		array_unshift($result, $key);
	}
	echo $result;
}	
*/
$file = file_get_contents ('quotes.json'); 
$file = json_decode($file);
$arr = array_merge((array)$arr, (array)$file);
if(isset($_GET["author"]))
{ 
	$result = array();
	foreach($arr as $key=>$value)
	{
		array_unshift($result, $key);
	}
	$a = array_key_exists($_GET["author"], $arr);
	if($a == true)
	{
		echo json_encode($arr[$_GET["author"]]);
	}
	else
	{
		echo "villa";
	}
}
elseif(isset($_GET["list"]) And isset($_GET["format"])) 
	if ($_GET["list"] == "authors" And $_GET["format"] == "pretty")
	{	
		echo "<dl>";
		foreach($arr as $key=>$value)
		{
			
			echo "<dt>\n";
			echo "<h1>\n";
			echo $key;
			echo "</h1>\n";
			echo "</dt>\n";
			
			foreach($value as $col)
			{
				echo "<dd>\n";
				echo $col;
				echo "</dd>\n";
			}
			
		}
		echo "</dl>";
	}
	else
	{
		echo "villa";
	}
elseif(isset($_GET["list"])) 
	if ($_GET["list"] == "authors") 
	{
		$result = array();
		foreach($arr as $key=>$value)
		{
			array_unshift($result, $key);
		}
		echo json_encode($result);
	}
	else
	{
		echo "villa";
	}
else echo "villa";
?>